package com.dcjt.firehotcarpad.moudle

import LocationPool
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.aries.library.fast.util.SizeUtil
import com.aries.ui.view.title.TitleBarView
import com.dcjt.firehotcarpad.R
import com.dcjt.firehotcarpad.fragment.MainOperationFragment
import com.dcjt.firehotcarpad.fragment.MapFragment1
import com.dcjt.firehotcarpad.utils.ServiceUtils
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_base_layout.*
import java.util.concurrent.TimeUnit

/**
 * Created by cj on 2021/2/20.
 * Email:codesexy@163.com
 * Function:
 * desc:无警情主页
 */
class NewMainActivity : BaseActivity() {

    override fun setTitleBarView(titleBar: TitleBarView) {
        titleBar.setLeftTextDrawable(R.drawable.logo1)
            .setLeftTextDrawableWidth(SizeUtil.dp2px(40f))
            .setLeftTextDrawableHeight(SizeUtil.dp2px(40f))
            .setLeftText(resources.getString(R.string.mainTitle))
            .setLeftTextSize(SizeUtil.dp2px(6f).toFloat())

    }

    override fun initView(savedInstanceState: Bundle?) {

        mainBottomContainer.visibility = View.GONE
        mapFragment = MapFragment1.newInstance()
        leftFragment = MainOperationFragment()
        supportFragmentManager
            .beginTransaction()
            .replace(R.id.leftContainer, leftFragment)
            .replace(R.id.rightContainer, mapFragment)
            .commitNow()

        // 开启定位服务
        LocationPool.get().start()
        ServiceUtils.startService(mContext)
        CarStatePool.get().start()
//        val subscribe = Observable.interval(15, TimeUnit.SECONDS)
//            .observeOn(Schedulers.io())
//            .subscribe {}
//
//        if (!subscribe.isDisposed) {
//            subscribe.dispose()
//        }

    }


    override fun onDestroy() {
        super.onDestroy()
        ServiceUtils.stopService(mContext)
    }


    override fun onBackPressed() {
        quitApp()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    }


}